class JQProductViewDetailService extends global.JQService {
	
	async _fetchPayments(o_id){
		console.log('do_action _fetchPayments 11111');
		
		const inst = global.JQTableIF.instance('pay_table',this.conn);
		//let inst_pay=global.
		console.log('do_action _fetchPayments 222222');
		
		let params_a=super._addUserParams();
		params_a = super._addParams(['o_id=',o_id],params_a);
		
		console.log('do_action 22222');
		let alias_keys=null;
		let a_keys=null;
		let alias_a_keys=null;
		let b_table='sign';				
		let b_keys=null;
		let alias_b_keys =['s_type','s_class'];
		let params_b =super._addParams(['u_id=',this.req_obj.u_id]);
		let joint='left join';
		let first= 0;
		let size = 100;	
		let on_a='p_class';
		let on_b= 's_type';
		let params=null;
		let order_by='p_time desc';
		let group_by =null;
		
		/////async query2(alias_keys,alias_a_keys, a_keys,a_params, b_table,alias_b_keys,b_keys,b_params,joint,on_a,on_b,params, first,size,group_by,order_by,is_count){}//(alias_a_keys, a_keys,a_params,alias_b_keys, b_table,b_keys,b_params,joint,on_a,on_b,params, first,size,group_by,order_by,is_count){}
		let list = await inst.query2(alias_keys,alias_a_keys,a_keys,params_a,
			b_table,alias_b_keys,b_keys,params_b,joint,
		   on_a,on_b,params,first,size,group_by,order_by);
		
		return list;			
	}
	
	
	async _fetchProducts(o_id){
		let inst_pay = global.JQTableIF.instance('order_detail_table',this.conn);
		
		let products = await inst_pay.query(null,['o_id=',o_id],0,100,null,null);
		return products;
	}
	
	
    async do_action(){
		console.log('view_detail 1111')
		if(!this.conn)console.log('do_action::conn error');
		let data_obj = this.req_obj.data_obj;
		if(!data_obj.cp_id)return null;
		let cp_id = data_obj.cp_id;
		console.log('cp_detail  ' + cp_id);
		let inst = global.JQTableIF.instance('cp_table',this.conn);
		let obj = await inst.get(cp_id);
		if(!obj)return null;
		// console.log('detail do_action 11111');
		// let payments= await this._fetchPayments(o_id);
		// if(payments)obj.payments = payments;
		// let items = await this._fetchProducts(o_id);
		// if(items)obj.items=items;
		
		let inst_menu = global.JQTableIF.instance('menu_table',this.conn);

		let menu_obj = await inst_menu.get(obj.menu_id,['menu_name']);
		if(menu_obj){
			obj.menu_name = menu_obj.menu_name;
		}
		// let menu_id = data_obj?data_obj.menu_id:null;
		
		let first=0;
		let size = 2000;	
		//async query2(alias_keys,alias_a_keys, a_keys,a_params, b_table,alias_b_keys,b_keys,b_params,joint,on_a,on_b,params, first,size,group_by,order_by,is_count){}//(alias_a_keys, a_keys,a_params,alias_b_keys, b_table,b_keys,b_params,joint,on_a,on_b,params, first,size,group_by,order_by,is_count){}
		// let list = await inst_menu.query(null,params,first,size,null,'sort desc');
		
		let inst_attr = global.JQTableIF.instance('cp_attribution_table',this.conn);
		
		let params=[['cp_id=',obj.cp_id],['attr_type=',1],['attr_status=',1]];
		let sizes = await inst_attr.query(null,params,first,size,null,'sort desc');
		params=[['cp_id=',obj.cp_id ],['attr_type=',2],['attr_status=',1]];
		let tastes = await inst_attr.query(null,params,first,size,null,'sort desc');
		
		let result ={obj:obj};
		let size_ids=[];
		let taste_ids=[];
		if(sizes && sizes.length>0){
			result.sizes=sizes;
			result.sizes.forEach((item)=>{size_ids.push(item.id)});
		}
		if(tastes && tastes.length>0){
			result.tastes=tastes;
			result.tastes.forEach((item)=>{taste_ids.push(item.id)});	
		}	
		
		
		let inst_attr_price = global.JQTableIF.instance('cp_attr_price_table',this.conn);
		if(size_ids.length || taste_ids.length){
			if(!size_ids.length)size_ids.push(0);
			if(!taste_ids.length)taste_ids.push(0);
			params=[['taste_id in ',taste_ids],[ 'size_id in',size_ids ]];
			let attr_prices = await inst_attr_price.query(null,params,first,size,null,null);
			if(attr_prices && attr_prices.length)result.attr_prices= attr_prices;
			console.log(JSON.stringify(attr_prices),size_ids,taste_ids);
		}
		
		
		return result;
	}

}
module.exports = JQProductViewDetailService;

